/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.applymatter.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nmf.site.common.PageDb;
import org.apache.commons.lang3.StringUtils;

import com.nmf.dao.gen.bean.BizApplyMatter;
import com.nmf.dao.gen.bean.BizApplyMatterExample;
import com.nmf.dao.gen.BizApplyMatterMapper;
import com.nmf.site.common.enums.DelFlagEnums;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.utils.IdGenerater;

/**
 * 注意事项Service
 * @author bm
 * @version 2019-01-25
 */
@Service
@Transactional(readOnly = true)
public class BizApplyMatterService{

	@Autowired
	BizApplyMatterMapper bizApplyMatterMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizApplyMatter get(String no) {
		return bizApplyMatterMapper.selectByPrimaryKey(no);
	}
	
	public List<BizApplyMatter> findList(BizApplyMatter bizApplyMatter) {
		BizApplyMatterExample bizApplyMatterExample = new BizApplyMatterExample();
		BizApplyMatterExample.Criteria criteria = bizApplyMatterExample.createCriteria();
		
		return bizApplyMatterMapper.selectByExample(bizApplyMatterExample);
	}
	
	public Page<BizApplyMatter> findPage(Page<BizApplyMatter> page, BizApplyMatter bizApplyMatter) {
		BizApplyMatterExample bizApplyMatterExample = new BizApplyMatterExample();
		BizApplyMatterExample.Criteria criteria = bizApplyMatterExample.createCriteria();
		
		bizApplyMatterExample.setPage(page);
		
		List<BizApplyMatter> dlist = bizApplyMatterMapper.selectByExample(bizApplyMatterExample);
		page.setList(dlist);
		page.setCount(bizApplyMatterMapper.countByExample(bizApplyMatterExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BizApplyMatter bizApplyMatter) {
		if(StringUtils.isNotEmpty(bizApplyMatter.getId())&&get(bizApplyMatter.getId())!=null) {
			bizApplyMatterMapper.updateByPrimaryKeySelective(bizApplyMatter);
		}else {
			Date date = new Date();
			bizApplyMatter.setCreateDate(date);
			bizApplyMatter.setId(idGenerater.genClsNo("bizApplyMatter"));
			bizApplyMatter.setUpdateDate(date);
			bizApplyMatterMapper.insertSelective(bizApplyMatter);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizApplyMatter bizApplyMatter) {
		bizApplyMatterMapper.deleteByPrimaryKey(bizApplyMatter.getId());
	}
	
}